package org.bridgen.runtime.inspect;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import org.bridgen.runtime.model.SOF;


public class RecoveryFrame extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	private RecoveryNodePanel textPanel;
	private JTabbedPane samplePane;
	private JLabel statusLabel;
	private boolean first = true;
	
	public RecoveryFrame() {
		
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
        panel.add(createTextPanel(), BorderLayout.CENTER);
		panel.add(createStatusPanel(), BorderLayout.SOUTH);
		getContentPane().add(panel);
		pack();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setPreferredSize(new Dimension(400, 600));
		setVisible(true);

	}
	
	public void displayText(SOF sof, String content, String title) {
		if (first) {
			samplePane.setTitleAt(0, title);
			first = false;
		} else {
			textPanel = new RecoveryNodePanel();
			addTextPanel(textPanel, title);
		}
		textPanel.displayNodes(sof);
		//textPanel.showInitResult(content);
		//textPanel.showLexerResult(sof);
		//textPanel.showRecoverResult();
	}
	
	private void addTextPanel(RecoveryNodePanel text, String title) {
		/*
		textPanel.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				showInfo(e);
			}
			public void mouseReleased(MouseEvent e) {
				showInfo(e);
			}
			private void showInfo(MouseEvent e) {
				showStatusForPoint(e.getPoint());
			}
		});
		*/
		JScrollPane scrollPane = new JScrollPane(text); 
		scrollPane.setPreferredSize(new Dimension(600,400));
		samplePane.addTab(title, scrollPane);
		samplePane.setSelectedComponent(scrollPane);
	}
	
	private JPanel createTextPanel() {
		JPanel panel = new JPanel();
		samplePane = new JTabbedPane();
		textPanel = new RecoveryNodePanel();
		
		addTextPanel(textPanel, "Tmp");
        panel.add(samplePane);
		return panel;
	}
	
	private JPanel createStatusPanel() {
		
		JPanel panel = new JPanel();
		statusLabel = new JLabel("Status...");
		panel.add(statusLabel);
		return panel;
	}
	
}